package com.feng.dt.controller;

import com.feng.common.db.querydsl.FetchResponse;
import com.feng.common.web.Range;
import com.feng.common.web.WebCommonResponse;
import com.feng.common.web.WebCommonResponseBuilder;
import com.feng.dt.service.SysMenuService;
import com.feng.profile.model.entity.SysMenu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping(value = "/sys/menu")
public class SysMemuController {

    private final static Logger LOGGER = LoggerFactory.getLogger(SysMemuController.class);

    @Autowired
    private SysMenuService sysMenuService;


    @PostMapping("/getAll.do")
    public WebCommonResponse<FetchResponse<SysMenu>> getAll(@RequestBody Range range) {
        FetchResponse<SysMenu> sysMenus = sysMenuService.getAllByPage(range);
        LOGGER.info(sysMenus.toString());
        return new WebCommonResponseBuilder<FetchResponse<SysMenu>>().build(sysMenus);
    }

    @PostMapping("/getAllAsMap.do")
    public WebCommonResponse<FetchResponse<Map<String,Object>>> getAllAsMap(@RequestBody Range range) {
        LOGGER.info("range:{}" , range);
        FetchResponse<Map<String,Object>> sysMenus = sysMenuService.getAllAsMap(range);
        LOGGER.info(sysMenus.toString());
        return new WebCommonResponseBuilder<FetchResponse<Map<String,Object>>>().success().build(sysMenus);
    }

}
